﻿$(function () {
    $('select').multiselect({
        header: false,
        minWidth: 280,
        selectedList: 1,
        multiple: false
    });

    function TranslatorSettingsChange(state) {
        var $settingsChange = $('#settingsChange');
        $settingsChange.removeClass('button-action-unchanged')
            .removeClass('button-action-unavalible')
            .removeClass('button-action-changed');

        var addClass = 'unchanged';
        switch (state) {
            case 'changed':
                addClass = 'changed';
                break;
            case 'unavalible':
                addClass = 'unavalible';
                break;
        }
        $settingsChange.addClass('button-action-' + addClass);
    }

    var resx = $('#translatorResource select').val();
    var ciFrom = $('#translatorFromLanguage select').val();
    var ciTo = $('#translatorToLanguage select').val();
    $('#translatorResource select, #translatorFromLanguage select, #translatorToLanguage select').change(function () {
        var cresx = $('#translatorResource select').val();
        var cciFrom = $('#translatorFromLanguage select').val();
        var cciTo = $('#translatorToLanguage select').val();
        if (resx == cresx && ciFrom == cciFrom && ciTo == cciTo)
            TranslatorSettingsChange('unchanged');
        else {
            if (cciFrom == cciTo)
                TranslatorSettingsChange('unavalible');
            else
                TranslatorSettingsChange('changed');
        }
    });
    var vth = $('#scrollAlwaysTop').height();
    var vbh = $(window).height();

    $('#normalScroll').css('margin-top', vth + 'px').css('height', (vbh - vth) + 'px');

    // support next untraslated
    $('#showOnlyUntranslatedContent').prettySelect();

    $('#iShowOnlyUntranslated').change(function () {
        if ($(this).prop('checked'))
            $('.translator-cell-transtext textarea:not(:empty)').parent().parent().hide();
        else
            $('.translator-row').show();
    });

    // support mark as translated
    $('.translator-row input[type=hidden]').val(0); // domyślnie jest jeden, przez co edytor przy zapisie stara się zapisać wszystkie, ale jak mamy obsługę js, to zapis jest przeprowadzany tylko na elementach zmienionych
    $('.translator-row textarea').keyup(function () {
        $(this).parent().find('input[type=hidden]').val(1);
    });
});